package com.ycz.config;/*
 @author ycz
 @date 2021-09-25-14:52  
*/

import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Configuration
public class MyConfig implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String loginEmail= (String) request.getSession().getAttribute("loginEmail");

        if (loginEmail==null){
            request.setAttribute("msg","你没有权限");
            request.getRequestDispatcher("/toLogin").forward(request,response);
            return false;
        }else {
            return true;
        }

    }


}
